home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
-
- #include "parse.h"
- #include <ctype.h>
- #include <string.h>
- #include <gl.h>
- #include <sys/types.h>
- #include <sys/stat.h>
-
- extern primitive *plist;
- extern long layerset;
-
- char *commenttitle()
- {
- static char tempbuf[256];
- char *sptr, *dptr;
-
- for (primitive *p = plist; p; p = p->next) {
- if (p->ptype == _text) {
- sptr = ((comment *)p)->str;
- dptr = tempbuf;
- while(*sptr) {
- if(isalnum(*sptr) || isspace(*sptr) || *sptr == '\''
- || *sptr == '-')
- *dptr++ = *sptr;
- sptr++;
- }
- *dptr=0;
- return tempbuf;
- }
- }
- return (char *)0;
- }
-
- #define XTRANS (306)
- #define YTRANS (469)
- #define PDELTA (252)
- #define FONTNAME "Times-Italic"
- #define oFONTNAME "ZapfChancery-MediumItalic"
-
- void setPScolor(long c, FILE *fp)
- {
- switch (c) {
- case 0:
- fprintf(fp, "1 1 1 setrgbcolor\n"); break;
- case 1:
- fprintf(fp, "1 0 0 setrgbcolor\n"); break;
- case 2:
- fprintf(fp, "0 1 0 setrgbcolor\n"); break;
- case 3:
- fprintf(fp, "1 1 0 setrgbcolor\n"); break;
- case 4:
- fprintf(fp, "0 0 1 setrgbcolor\n"); break;
- case 5:
- fprintf(fp, "1 0 1 setrgbcolor\n"); break;
- case 6:
- fprintf(fp, "0 1 1 setrgbcolor\n"); break;
- case 7:
- fprintf(fp, "0 0 0 setrgbcolor\n"); break;
- default:
- fprintf(fp, "0 0 0 setrgbcolor\n"); break;
- }
- }
-
- long EPS = 0;
-
- long dumpPostScript(char *filename)
- {
- float ym = 0.0;
- FILE *fp;
- char *comment;
- char str[100];
-
- if (EPS == 1) filename = "geom.ps";
- mode_t omask = umask(0);
- fp = fopen(filename, "w");
- umask(omask);
- if (fp == 0) {
- sprintf(str, "Couldn't open %s", filename);
- displaymessage(str);
- return 0;
- }
- fprintf(fp,"%%!PS-Adobe-2.0 EPSF-1.2\n");
- fprintf(fp,"%%%%Creator: tops on IRIS workstation\n");
- fprintf(fp,"%%%%BoundingBox: %d %d %d %d\n",306-PDELTA,YTRANS-PDELTA,306+PDELTA,YTRANS+PDELTA);
- fprintf(fp,"%%%%EndComments\n");
- fprintf(fp, "0 setlinewidth\n");
- fprintf(fp, "%d %d translate\n",XTRANS,YTRANS);
- fprintf(fp, "%d %d scale\n",PDELTA,PDELTA);
- fprintf(fp,"/haloshow {\n");
- fprintf(fp,"gsave\n");
- fprintf(fp,"0.010 setlinewidth\n");
- fprintf(fp,"1 setlinecap\n");
- fprintf(fp,"1 setlinejoin\n");
- fprintf(fp,"currentrgbcolor\n");
- fprintf(fp,"/bval exch store /gval exch store /rval exch store\n");
- fprintf(fp,"1 setgray\n");
- fprintf(fp,"gsave\n");
- fprintf(fp,"dup false charpath stroke\n");
- fprintf(fp,"grestore\n");
- fprintf(fp,"gsave\n");
- fprintf(fp,"dup show\n");
- fprintf(fp,"grestore\n");
- fprintf(fp,"rval gval bval setrgbcolor show\n");
- fprintf(fp,"grestore\n");
- fprintf(fp,"} def\n");
- fprintf(fp, "/centershow {\n");
- fprintf(fp, "dup\n");
- fprintf(fp, "stringwidth pop -2 div 0 rmoveto\n");
- fprintf(fp, "haloshow\n");
- fprintf(fp, "} def\n");
- comment = commenttitle();
- if(comment) {
- fprintf(fp, "/%s findfont .084 scalefont setfont\n",FONTNAME);
- fprintf(fp, "0.0 -1.2 moveto (%s) centershow\n",comment);
- }
- fprintf(fp, "-1 -1 moveto -1 1 lineto 1 1 lineto 1 -1 lineto\n");
- fprintf(fp, "closepath clip\n");
- fprintf(fp, "/%s findfont .060 scalefont setfont\n",FONTNAME);
- for (primitive *p = plist; p; p = p->next) {
- setPScolor(p->Color, fp);
- if (layerset & p->layers) switch (p->ptype) {
- case _vertex:
- break;
- case _line:
- ((line *)p)->PostScript(fp); break;
- case _circle:
- ((circle *)p)->PostScript(fp); break;
- case _bezier:
- ((bezier *)p)->PostScript(fp); break;
- case _length:
- if (p->name[0] == 0) break;
- fprintf(fp, "-0.99 %f moveto\n", ym);
- ym -= 2.3*pbsize;
- ((length *)p)->PostScript(fp);
- break;
- case _conic:
- ((conic *)p)->PostScript(fp); break;
- case _text:
- break;
- }
- }
- for (p = plist; p; p = p->next) {
- setPScolor(p->Color, fp);
- if (p->ptype == _vertex && (layerset & p->layers))
- ((vertex *)p)->PostScript(fp);
- }
- fprintf(fp, "showpage\n");
- fclose(fp);
- if (EPS == 0) {
- sprintf(str, "lp -c %s; rm %s", filename, filename);
- system(str);
- }
- return 1;
- }
-
- long readgeometry(char *filename)
- {
- FILE *fp;
- char str[100];
- if (0 == (fp = fopen(filename, "r"))) {
- sprintf(str, "Couldn't open %s", filename);
- displaymessage(str);
- return 0;
- }
- return parsefile(fp);
- }
-
- #include <time.h>
-
- char *suffix = 0;
-
- long insertgeometry(char *filename)
- {
- char insertprefix[15];
- long i = (long)time(0);
- sprintf(insertprefix, "__%x", (i&0x7ffff8)>>3);
- suffix = insertprefix;
- long ret = readgeometry(filename);
- suffix = (char *)0;
- return ret;
- }
-